﻿using Heng.Elements.Core.Model.Infrastructure.Messages;
using Heng.Elements.Core.Model.Infrastructure.Policy;
using Heng.Elements.Core.Model.Infrastructure.Repositories;
using Heng.Elements.Core.Model.Infrastructure.Services;
using Heng.Elements.ERD.Model.Entities;
using Heng.Elements.ERD.Model.Repositories;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Heng.Elements.ERD.Model.Services
{
    /// <summary>
    /// Domain entity attribute service.
    /// </summary>
    public class DomainEntityAttributeService : EntityServiceBase<DomainEntityAttribute>
    {
        public DomainEntityAttributeService(EntityRepositoryContext ctx)
            :base(ctx)
        {
        }

        /// <summary>
        /// Get entity attributes by entity ID.
        /// </summary>
        /// <param name="entityId"> Entity ID. </param>
        /// <returns> Entity attributes. </returns>
        public ServiceResponse<IEnumerable<DomainEntityAttribute>> GetByEntity(long entityId)
        {
            var response = this.ExecInContext<IEnumerable<DomainEntityAttribute>>((ctx, res) =>
                {
                    var repo = ctx.GetRepository<IDomainEntityAttributeRepository>();
                    var entAttributes = repo.GetByEntity(entityId);
                    return entAttributes;
                });

            return response;
        }
    }
}
